package com.snake.springboot.custom.controller.points;

import com.snake.springboot.custom.api.model.base.CallbackModel;
import com.snake.springboot.custom.api.model.points.PointsRgeRecordModel;
import com.snake.springboot.custom.api.request.page.PageQuery;
import com.snake.springboot.custom.api.request.points.PointsRechargeReq;
import com.snake.springboot.custom.api.request.points.PointsRetReq;
import com.snake.springboot.custom.api.request.points.PointsRgeRecordQuery;
import com.snake.springboot.custom.api.response.points.PointsRechargeRsp;
import com.snake.springboot.custom.api.service.points.PointsRgeRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.snake.common.result.ReturnList;
import org.snake.common.validate.Create;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>算力管理-算力充值记录
 * 类{@code PointsRgeRecord} </br>
 * 创建时间2025/2/20 17:40
 * @author yangxt
 * @see
 */
@Api(tags = "算力管理-算力充值记录")
@RestController
@RequestMapping("points/rge-record")
public class PointsRgeRecordController {

    private PointsRgeRecordService recordService;
    @Autowired
    public PointsRgeRecordController(PointsRgeRecordService recordService) {
        this.recordService = recordService;
    }

    @ApiOperation("新增")
    @PostMapping("/add")
    public ResponseResult<PointsRgeRecordModel> addPointsRgeRecord(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody @Validated({Create.class}) PointsRgeRecordModel model) {
        PointsRgeRecordModel result = recordService.addPointsRgeRecord(model);
        return ResponseResultFactory.ucc("添加成功！", result);
    }

    @ApiOperation("充值")
    @PostMapping("/recharge")
    public ResponseResult<PointsRechargeRsp> recharge(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody @Validated({Create.class}) PointsRechargeReq model) {
        PointsRechargeRsp result = recordService.recharge(model);
        return ResponseResultFactory.ucc("添加成功！", result);
    }

    @PostMapping("/callback")
    public ResponseResult<Object> callback(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody CallbackModel model) {
        recordService.callback(model);
        return ResponseResultFactory.ucc("回调成功！");
    }


    @ApiOperation("退款")
    @PostMapping("/points-ret")
    public ResponseResult<PointsRechargeRsp> pointsRet(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody PointsRetReq model) {
        recordService.pointsRet(model);
        return ResponseResultFactory.ucc("退款成功！");
    }

    @ApiOperation("修改")
    @PostMapping("/modify")
    public ResponseResult<PointsRgeRecordModel> modifyPointsRgeRecord(
            @ApiParam(name = "接口模型入参", value = "传入json格式", required = true)
            @RequestBody PointsRgeRecordModel model) {
        recordService.modifyPointsRgeRecord(model);
        return ResponseResultFactory.ucc("修改成功！");
    }

    @ApiOperation("删除")
    @GetMapping("/remove/{id}")
    public ResponseResult<Object> remove(
            @ApiParam(name = "记录ID", value = "传入String类型", required = true)
            @PathVariable("id") String id) {
        recordService.removePointsRgeRecord(id);
        return ResponseResultFactory.ucc("移除成功！");
    }

    @ApiOperation("查询列表")
    @PostMapping("/list")
    public ResponseResult<ReturnList<PointsRgeRecordModel>> queryPointsRgeRecordList(
            @ApiParam(name = "查询条件", value = "传入json类型", required = true)
            @RequestBody PageQuery<PointsRgeRecordQuery> params) {
        params.getParams().setCustomId(params.getCustomId());
        ReturnList<PointsRgeRecordModel> result = recordService.queryPointsRgeRecordList(params);
        return ResponseResultFactory.ucc("查询成功！", result);
    }
}
